1. Field of the Invention
The present invention pertains to the field of computer graphics, and in particular, to multiple texture rendering.
2. Related Art
Computer systems are commonly used for displaying graphical objects on a display screen. These graphical objects include points, lines, polygons, and three dimensional solid objects. By utilizing texture mapping techniques, color and other details can be applied to areas and surfaces of these objects. In texture mapping, a pattern image, also referred to as a xe2x80x9ctexture map,xe2x80x9d is combined with an area or surface of an object to produce a modified object with the added texture detail. For example, given the outline of a featureless cube and a texture map defining a wood grain pattern, texture mapping techniques can be used to xe2x80x9cmapxe2x80x9d the wood grain pattern onto the cube. The resulting display is that of a cube that appears to be made of wood. In another example, vegetation and trees can be added by texture mapping to an otherwise barren terrain model. Likewise, labels can be applied onto packages or cans to visually convey the appearance of an actual product. Textures mapped onto geometric surfaces provide motion and spatial cues that surface shading alone might not provide. For example, a sphere rotating about its center appears static until an irregular texture or pattern is affixed to its surface.
Multiple texture rendering techniques are used to render multiple textures on a single primitive. Many complex computer graphics effects are implemented by rendering multiple textures on a primitive and blending these textures together. One method of multiple texture rendering is to do a xe2x80x9ccoarsexe2x80x9d grain multi-pass. Each texture is handled in succession by a single texture processing hardware unit. A coarse grain multi-pass process first renders all of the primitives of an object for a single texture, and then renders the object with the next texture, until all textures are complete. Blending between textures is limited to frame buffer operations. The coarse grain multi-pass technique requires geometry to be sent multiple times from a geometry engine to a raster subsystem. Therefore, a coarse grain multi-pass technique is slow and involves considerable overhead. On the other hand, a coarse grain multi-pass technique requires only one texture processing hardware unit.
A second multiple texture rendering technique, which is now just appearing on personal computer (PC) level products, is to have multiple texture units in the hardware connected together by texture blending units. This parallel approach to multiple texture rendering has the advantage of being able to render multiple textures simultaneously, thereby, completing the multiple textures in one pass. See, for example, U.S. Pat. No. 5,740,343 issued to Tarolli et al. Tarolli combines multiples textures in a single pass using a texture compositing unit (TCU) 114. However, TCU 114 uses a cascade of multiple copies of texture mapping units (TMUs) 210A-C (FIG. 2 and col. 7, lns. 24-27). This technique has the disadvantage of being expensive because multiple copies of the texture unit hardware (TMUs) are required to render multiple textures in a single pixel rendering pass. This technique has the further disadvantage that if multiple textures are not being used, the additional copies of texture hardware are not used.
A multiple texture rendering technique is needed that is faster than coarse grain multiple texture rendering and less expensive than a parallel approach using multiple redundant copies of texture hardware.
The present invention provides a system and method for multiple texture rendering on a primitive using a fine grain multi-pass at a pixel level. In one embodiment, a computer graphics raster subsystem renders multiple textures on a primitive. A fine grain scan converter takes in a primitive description with one color and multiple sets of texture coordinates defined for each vertex. Each set of texture coordinates defines an independent texture. Each texture is associated with a texture number. The fine grain scan converter produces fragments. Each fragment corresponds to a single pixel and includes color and a set of texture coordinates for each of the multiple textures. Each fragment can also include other information such as screen position and depth. A texture address generator and texture filter use the texture numbers and their associated texture coordinates to produce a filtered texture value for each of the multiple textures. For multiple textures there will be two or more texture values. Of course, the hardware can handle the case where there is only one or even no texture values. A recirculating texture blender combines these filtered texture values with the fragment color to produce a final textured fragment color. The recirculating texture blender can also output intermediate results in producing the-textured fragment color.
According to one embodiment of the present invention, the fine grain scan converter has a scan converter, a fragment color calculator, a replicator, and a texture coordinate calculator. The scan converter produces one position per pixel. The fragment color calculator calculates a color per pixel from the vertex colors and the pixel position. The replicator makes multiple copies of the pixel position information. The number of copies corresponds to the number of textures. The replicator assigns each copy a unique texture number. The texture coordinate calculator calculates texture coordinates in texture space from the vertex texture coordinates and the pixel position.
The texture memory address generator accesses texels identified by the texture coordinates output from the fine grain scan converter. The texture filtering block (also called a texture filter) filters texels output from the texture memory address generator to produce a single filtered texture value associated with a texture number being processed. The recirculating texture blender combines a color and multiple filtered textures to yield a single textured fragment color value. The recirculating texture blender can also pass texture information to other blocks in a graphics subsystem, such as a lighting block.
One feature of the present invention is that a single texture processing hardware unit can be used to perform multiple texture rendering on a primitive in a fine grain multi-pass on a pixel level. In one preferred embodiment, each of the texture coordinate calculator in a fine grain scan converter, the texture address generator, the texture filter, and the recirculating texture blender comprise stages of a single texture processing hardware unit. The single texture processing hardware unit includes hardware capable of processing one texture and either hardware, software, and/or firmware capability to hold state information associated with several textures. The hardware rapidly switches between processing different textures and allows a very fine grain multi-pass implementation of multiple texture rendering.
In one example implementation, the single texture processing hardware unit includes a texture processing unit, a texture state register, a texture enablement register, and a switch or multiplexer (switch/multiplexer). The texture processing unit performs texture processing including the stages of texture coordinate calculation, texture address generation, texture filtering, and recirculating texture blending. The texture state register stores state information associated with each texture during the texture processing. The texture enablement register stores information identifying whether each texture is enabled. The switch or multiplexer selects which enabled texture is to be processed by the texture processing unit based on a received texture number and the texture enablement register.
A method of the present invention comprises the steps of (a) storing state information associated with each of multiple textures in texture state registers; (b) storing enablement information in texture enablement registers identifying whether each multiple texture is enabled; (c) assigning texture numbers identifying textures; (d) at stages of multiple texture rendering, switching to couple a texture processing unit to a texture state register corresponding to a texture identified by a texture number assigned in the step (c); and (e) processing each texture based on state information in the texture state register when the texture enablement register identifies an enabled texture. Steps (d) and (e) are repeated until all of the assigned texture numbers in step (c) have been received and all enabled textures have been processed in rendering the primitive.
In one example, the texture processing step (e) includes stages of multiple texture rendering comprising steps of texture coordinate calculation in fine grain scan converting, texture addressing, texture filtering, and recirculating texture blending. In fine grain scan converting, the primitive defined by the input vertices is rasterized to fragments such that for each pixel is produced the required texture coordinates for each of the multiple textures along with their corresponding texture numbers. The resulting texture coordinates are rendered through texture addressing and texture filtering steps into filtered texture values for each of the multiple textures. The recirculating texture blending step combines these multiple textures with a base fragment color to produce a final color.
A fine-grain multi-pass technique for rendering multiple textures on a primitive, as in the present invention, is faster than a coarse grain multi-pass technique because the geometry does not need to be sent multiple times from a geometry engine to a raster subsystem. In addition, the fine-grain multi-pass technique of the present invention is cheaper and more efficient than a parallel approach because it does not require multiple dedicated texture units in hardware connected together by multiple dedicated texture blending units.
Further embodiments, features, and advantages of the present invention, as well as the structure and operation of various embodiments of the present invention, are described in detail below with reference to the accompanying drawings.